import { Logger } from "@nestjs/common";
import { IConfig } from "./configuration";

// 判断系统是否是开发环境
export function isDev(): boolean {
  return process.env.NODE_ENV === 'development';
}

// 根据环境变量返回对应的配置
export default () => {
  let envConfig: IConfig = {};
  let NODE_ENV = process.env.NODE_ENV || "development"
  try {
    envConfig = require(`./config.${NODE_ENV}`).default;

  } catch (e) {
    const logger = new Logger('ConfigModule');
    logger.error(e);
  }

  // 返回环境配置
  return envConfig;
};
